//
//  ExperienceTableViewCell.m
//  BTRIP
//
//  Created by johnbk on 15/11/14.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "ExperienceTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@implementation ExperienceTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)dealloc{
	[_buttonOfLocation release];
	[_imageViewOfTime release];
	[_imageViewOfUrl release];
	[_labelOfConsumption_per_person release];
	[_labelOfDistance release];
	[_labelOfName release];
	[_labelOfTime release];
	[_experienceModel release];
	[super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		[self createView];
	}
	return  self;
}
- (void)createView{
	self.imageViewOfUrl = [[UIImageView alloc]init];
	[self.contentView addSubview:self.imageViewOfUrl];
	[self.imageViewOfUrl release];
	
	self.labelOfName = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfName];
	[self.labelOfName release];
	
	self.imageViewOfTime = [[UIImageView alloc]init];
	[self.contentView addSubview:self.imageViewOfTime];
	[self.imageViewOfTime release];
	self.imageViewOfTime.image = [UIImage imageNamed:@"iconfont-shijian"];
	
	self.labelOfTime = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfTime];
	[self.labelOfTime release];
	
	self.buttonOfLocation = [UIButton buttonWithType:UIButtonTypeCustom];
	[self.contentView addSubview:self.buttonOfLocation];
	[self.buttonOfLocation setBackgroundImage:[UIImage imageNamed:@"iconfont-icon30"] forState:UIControlStateNormal];

	self.labelOfDistance = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfDistance];
	[self.labelOfDistance release];
	
	self.labelOfConsumption_per_person = [[UILabel alloc]init];
	[self.contentView addSubview:self.labelOfConsumption_per_person];
	[self.labelOfConsumption_per_person release];
	
}
- (void)layoutSubviews{
	[super layoutSubviews];
	self.imageViewOfUrl.frame = CGRectMake(20, 10, self.frame.size.width - 40, 170);
	self.labelOfName.frame = CGRectMake(self.imageViewOfUrl.frame.origin.x, self.imageViewOfUrl.frame.origin.y + 10 + self.imageViewOfUrl.frame.size.height, self.imageViewOfUrl.frame.size.width, 30);
	self.labelOfName.font = [UIFont systemFontOfSize:14];
	self.imageViewOfTime.frame = CGRectMake(self.imageViewOfUrl.frame.origin.x, self.labelOfName.frame.origin.y + 10 + self.labelOfName.frame.size.height, 20, 20);
	self.labelOfTime.frame = CGRectMake(self.imageViewOfTime.frame.origin.x + 10 + self.imageViewOfTime.frame.size.width, self.imageViewOfTime.frame.origin.y, 60, self.imageViewOfTime.frame.size.height);
	self.labelOfTime.font = [UIFont systemFontOfSize:9];
	self.labelOfTime.textColor = [UIColor darkGrayColor];
	self.buttonOfLocation.frame = CGRectMake(self.labelOfTime.frame.origin.x + 20 + self.labelOfTime.frame.size.width, self.imageViewOfTime.frame.origin.y, self.imageViewOfTime.frame.size.width, self.imageViewOfTime.frame.size.height);
	self.labelOfDistance.frame = CGRectMake(self.buttonOfLocation.frame.origin.x + 10 + self.buttonOfLocation.frame.size.width, self.imageViewOfTime.frame.origin.y, self.labelOfTime.frame.size.width, self.labelOfTime.frame.size.height);
	self.labelOfDistance.font = self.labelOfTime.font;
	self.labelOfDistance.textColor = self.labelOfTime.textColor;
	self.labelOfConsumption_per_person.frame = CGRectMake(self.frame.size.width - 100, self.imageViewOfTime.frame.origin.y - 5, self.labelOfTime.frame.size.width + 20, self.labelOfTime.frame.size.height + 10);
	self.labelOfConsumption_per_person.font = [UIFont systemFontOfSize:11.5];
	//self.labelOfName.backgroundColor = [UIColor redColor];
}
- (void)setExperienceModel:(ExperienceModel *)experienceModel{
	if (_experienceModel != experienceModel) {
		[_experienceModel release];
		_experienceModel = [experienceModel retain];
		[self.imageViewOfUrl sd_setImageWithURL:[NSURL URLWithString:experienceModel.url] placeholderImage:[UIImage imageNamed:@"background"]];
		self.labelOfName.text = experienceModel.name;
		self.labelOfTime.text = experienceModel.active_time;
		self.labelOfDistance.text = [NSString stringWithFormat:@"%.1fKM", [experienceModel.distance floatValue] / 1000];
		self.labelOfConsumption_per_person.text = [NSString stringWithFormat:@"￥%@/人均", experienceModel.consumption_per_person];
	
	}
}
+(ExperienceTableViewCell *)tableView:(UITableView *)tableView{
	static NSString *cellIdentifier = @"ExperienceTableViewCellIdentifer";
	ExperienceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
	if (!cell) {
		cell = [[ExperienceTableViewCell alloc]init];
	}
	return cell;
}

@end
